<?php

namespace app\admin\controller;  
use app\admin\model\Clbum;

/**
 * 后台首页控制器
 */
class Index extends Admin  {

    public function test() 
    {
        $timestr = time();
        $now_day = date('w',$timestr) ?: 7;
        dump($now_day);
        //获取一周的第一天，注意第一天应该是星期天
        $sunday_str = $timestr - ($now_day-1)*60*60*24;
        $sunday = date('Y-m-d', $sunday_str);
        //获取一周的最后一天，注意最后一天是星期六
        $strday_str = $timestr + (7-$now_day)*60*60*24;
        $strday = date('Y-m-d', $strday_str);
        echo "星期1： $sunday\n";
        echo "星期天： $strday\n";
        
        $date=new \DateTime();
        $time = $date->format('Y-m-d H:i:s');
        dump($time);
        $date->modify('this week');
        $first_day_of_week=$date->format('Y-m-d');
        dump($first_day_of_week);
        $date->modify('this week +6 days');
        $end_day_of_week=$date->format('Y-m-d');
        dump($end_day_of_week);
        $data = weekFormat();
        dump($data);
    }
    /**
     * 后台首页
     */
    public function index(){ 
        $this->assign('meta_title','管理首页') ;
        //获取一周的班级数据
        $lists = Clbum::all();
        $lists = $lists->toArray();
        $return = [];
        $week = weekFormat();
        foreach ($lists as $key=>$value) {
            $return[$key] = [
                'title'=>$value['name'].'|'.get_course($value['course_id']),
                'start'=>$week[$value['day_week']].'T'.$value['start_time'],
                'end'=>$week[$value['day_week']].'T'.$value['end_time'],
                'url'=>url('Clbum/student',['id'=>$value['id']])
            ];
        }
        $this->assign('_lists', json_encode($return, JSON_UNESCAPED_UNICODE));
        return $this->fetch();
    }

}
